home *** CD-ROM | disk | FTP | other *** search
- /*
- * mmaux.c : the tokens MM don't know about
- * Craig Durland 6/87
- */
-
- /* Copyright 1990, 1991, 1992 Craig Durland
- * Distributed under the terms of the GNU General Public License.
- * Distributed "as is", without warranties of any kind, but comments,
- * suggestions and bug reports are welcome.
- */
-
- #include <stdio.h>
- #include <os.h>
-
- extern int MMask_pgm; /* in mm.c */
- extern char result[]; /* in mm.c */
-
- #include "mm.h"
- extern uint8 *MMglobal_vars;
- extern MMDatum RV, TV; /* in mm.c */
- void MMbitch();
-
- main(argc,argv) char *argv[];
- {
- extern int MMask_pgm;
-
- MMask_pgm = TRUE;
-
- MMinitialize();
- MMload(argv[1],TRUE); /* load and go */
- exit(0);
- }
-
- void MMset_hooks() {} /* No hooks used by this stuff */
- void MMgc_external_objects() {} /* No external objects */
-
- MMaux_fcn(name) char *name; { return FALSE; }
- void MMxtoken(token) { MMbitch("Invalid Xtoken"); }
-
- MMask(prompt,buf) char *prompt, *buf;
- {
- printf("%s",prompt); gets(buf); return TRUE;
- }
-
- void MMmsg(str) char *str; { puts(str); }
-
- void MMbitch(msg) char *msg;
- { printf("PGM ABORT(%u): %s\n",decodepc(),msg); MMabort_pgm(2); }
-
- void MMmoan(msg) char *msg; { puts(msg); }
-
- /*************************************************************************
- ****************** pgm management ****************************************
- **************************************************************************/
-
- typedef struct /* programs */
- {
- char *name; /* ascii name of command */
- maddr addr; /* address of routine */
- } PGM;
-
- #define PGMMAX 100
-
- PGM pgms[PGMMAX];
- int pbsize = 0;
- static maddr codeblock;
-
- maddr MMpgm_addr(n) { return pgms[n].addr; }
-
- maddr pcat();
- decodepc() { return (int)(pcat() -codeblock); }
-
- /* MMopen_code_file(name): open the code file.
- * name munged to contain name of opened file.
- * returns: ptr to opened file
- */
- FILE *MMopen_code_file(name) char *name;
- {
- return fopen(name,"rb");
- }
-
- MMadd_pgm(name,tag,addr) char *name; maddr addr;
- {
- if (pbsize >= PGMMAX) { MMmoan("pgm table OD"); return FALSE; }
- pgms[pbsize].name = name; pgms[pbsize].addr = addr; pbsize++;
- return TRUE;
- }
-
- void MMblock_name(buf,fname) char *buf,*fname; /* create the block name */
- {}
-
- MMadd_block(name,code,global_vars, global_object_table,num_global_objects)
- char *name; maddr code; uint8 *global_vars;
- void *global_object_table; int num_global_objects;
- {
- codeblock = code;
- return 0;
- }
-
- /* Use binary search to find pgm
- * returns index of token if found
- * -1 if not found
- */
- MMpgm_lookup(name) char *name;
- {
- register int j, lower=0, upper=pbsize-1, x;
-
- while (lower<=upper)
- {
- j = (lower+upper)/2;
- if ((x = strcmp(name,pgms[j].name))>0) lower = j +1;
- else if (x<0) upper = j -1; else return j;
- }
- return -1;
- }
-